//
//  JMDrawingArrowLayer.swift
//  JMDrawingLayer
//
//  Created by JunMing on 2021/1/29.
//

import UIKit

// 绘制单箭头直线
class JMDrawingArrowLayer: JMDrawingBaseLayer {
    public func movePath(endPoint point: CGPoint) {
        if let sPoint = self.startPoint {
            self.endPoint = point
            let path = UIBezierPath()
            path.move(to: sPoint)
            path.addLine(to: point)
            path.append(arrowWithPoint(startPoint: sPoint, endPoint: point))
        }
    }
}

// 绘制直线
class JMDrawingLineLayer: JMDrawingBaseLayer {
    public func movePath(endPoint point: CGPoint) {
        if let sPoint = self.startPoint {
            self.endPoint = point
            let path = UIBezierPath()
            path.move(to: sPoint)
            path.addLine(to: point)
            self.path = path.cgPath
        }
    }
}

// 绘制虚线
class JMDrawingDashlineLayer: JMDrawingBaseLayer {
    public func movePath(endPoint point: CGPoint) {
        if let sPoint = self.startPoint {
            self.endPoint = point
            
            lineDashPattern = [NSNumber(value: 10),NSNumber(value: 5)]
            let cgPath = CGMutablePath()
            cgPath.move(to: sPoint)
            cgPath.addLine(to: point)
            
            let path = UIBezierPath(cgPath: cgPath)
            self.path = path.cgPath
        }
    }
}
